//下降效果
function Down_Diamend(){

    this.width = 0;
    this.height = 0;
    this.lastPosX = 0;
    this.lastPosY = 0;
    this.posX = 0;
    this.posY = 0;
    this.visible = false;

    var MapLeft = 0;
    var MapTop = 0;
    var MapRight = 0;
    var MapBottom = 0;

    this.speedX = 0;
    this.speedY = 0;
    this.acceleration = 0;

    this.frameCount = 0;
    this.frameIndex = 0;
    this.frameTotal = 0;
    this.imgs;

    this.catchScore = 0;

    this.InitEffect = function(width, height, SW, SH, speedX, speedY, centerX, centerY, imgs, catchScore) {
        this.width = width;
        this.height = height;

        MapLeft = -width;
        MapTop = -height;
        MapRight = SW;
        MapBottom = SH;

        this.speedX = speedX;
        this.speedY = speedY;
        this.posX = centerX-width/2;
        this.posY = centerY - height/2;
        this.lastPosX = this.posX;
        this.lastPosY = this.posY;
        this.visible = true;
        this.imgs = imgs;
        this.catchScore = catchScore;

        this.acceleration = 1;

        this.frameCount = 3;
        this.frameTotal = imgs.length;
        this.frameIndex = randomNextInt(0,this.frameTotal-1);

        this.visible = true;
    };

    this.update = function(){
        if(this.visible){
            if(this.frameCount == 0){
                this.frameIndex++;
                if(this.frameIndex == this.frameTotal){
                    this.frameIndex = 0;
                }
            }
            this.frameCount--;
            if(this.frameCount < 0){
                this.frameCount = 3;
            }

            //更新位置
            this.lastPosX = this.posX;
            this.lastPosY = this.posY;
            this.posX = this.posX + this.speedX;

            var tempY = this.speedY + this.acceleration;
            if(Math.abs(tempY) >= Math.abs(this.speedY))
            {
                this.posY = this.posY + (tempY*tempY - this.speedY*this.speedY)/(2*this.acceleration);
            }
            else
                this.posY = this.posY - (this.speedY*this.speedY - tempY*tempY)/(2*this.acceleration);

            this.speedY = tempY;

            if(this.lastPosY > MapBottom && this.posY > MapBottom){
                this.visible = false;
            }
        }
    }



    this.paint = function(drawCanvas){
        if(this.visible){
            drawCanvas.drawImage(this.imgs[this.frameIndex], this.posX, this.posY);
        }
    }
}